package myky.com.doctorapp.presenter;

import java.util.List;

import io.reactivex.disposables.Disposable;
import myky.com.doctorapp.api.ResponseTransformer;
import myky.com.doctorapp.api.schedulers.SchedulerHelper;
import myky.com.doctorapp.base.BasePresenterIm;
import myky.com.doctorapp.base.SimpleSubscribe;
import myky.com.doctorapp.contract.DoctorDeatailsContract;
import myky.com.doctorapp.entity.DoctorEntity;
import myky.com.doctorapp.entity.TeamEntity;
import myky.com.doctorapp.model.DoctorDeatailsModel;

public class DoctorDeatailsPresenter extends BasePresenterIm<DoctorDeatailsContract.View> implements DoctorDeatailsContract.Presenter {

    private DoctorDeatailsModel doctorDeatailsModel;

    public DoctorDeatailsPresenter() {
        doctorDeatailsModel = new DoctorDeatailsModel();
    }

    @Override
    public void getDoctorDeatails(String doctorId, String version) {

        doctorDeatailsModel.getDoctorDeatails(doctorId, version)
                .compose(ResponseTransformer.handleResult())
                .compose(SchedulerHelper.applySchedulers())
                .subscribe(new SimpleSubscribe<DoctorEntity.PayLoadEntity>() {
                    @Override
                    protected void onSuccess(DoctorEntity.PayLoadEntity doctorEntity) {
                        mView.showDoctorDeatails(doctorEntity);
                        mView.hideLoading();
                    }

                    @Override
                    protected void onFailed(String msg) {
                        mView.logCat(msg);
                        mView.hideLoading();
                    }

                    @Override
                    public void onSubscribe(Disposable d) {
                        addSubscription(d);
                        mView.showLoadingView("请稍后");
                    }
                });


    }

    @Override
    public void getTeamInfo(String version, String doctorid) {
        doctorDeatailsModel.getTeamInfo(version, doctorid)
                .compose(ResponseTransformer.handleResult())
                .compose(SchedulerHelper.applySchedulers())
                .subscribe(new SimpleSubscribe<List<TeamEntity.DataEntity>>() {
                    @Override
                    protected void onSuccess(List<TeamEntity.DataEntity> teamEntityList) {
                        mView.showTeams(teamEntityList);
                    }

                    @Override
                    protected void onFailed(String msg) {
                        mView.showDataError(msg);

                    }

                    @Override
                    public void onSubscribe(Disposable d) {
                        addSubscription(d);
                    }
                });
    }
}
